<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of controller
 *
 * @author user
 */
class Controller {
    protected   $view = 'view';
    public      $load;
    public      $config;
    public      $router;
    private static $instance;

    public function __construct() {
        self::$instance = $this;
        require_once BASEPATH . 'core/loader.php';
        require_once BASEPATH . 'core/config.php';
        require_once BASEPATH . 'core/common.php';
        require_once BASEPATH . 'core/view.php';

        $this->load = new Loader();
        $this->config = new Config();

        if($this->config->item('use_database')) {
            spl_autoload_register('load_db');
        }

        $this->view = View::factory($this->view);
    }

    /**
     * This function is always call before "request method"
     *
     * Example :
     *
     * Request localhost/user/login. "user" is controller and "login" is method.
     * Method "_before" is called before method "login".
     *
     * @return  void
     */
    public function _before() {
        
    }

    /**
     * This function is always call after "request method"
     *
     * Example :
     *
     * Request localhost/user/login. "user" is controller and "login" is method.
     * After method "login" is called the "_after" method will be called.
     *
     * @return  void
     */
    public function _after() {
        $this->render_view();
    }

    /**
     * Call view->render and print its content
     *
     * @return  void
     */
    public function render_view() {
        echo $this->view->render();
    }

    public static function &get_instance() {
        return self::$instance;
    }
}
?>
